package com.dawnClass.controller;


import com.dawnClass.pojo.Note;
import com.dawnClass.pojo.Video;
import com.dawnClass.service.NoteService;
import com.dawnClass.service.VideoService;
import com.dawnClass.util.ServiceResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
public class NoteController {
    @Autowired
    private NoteService noteService;

    @Autowired
    private VideoService videoService;

    @GetMapping("/note/{chapterId}/{pageNum}")
    public ServiceResponse getNote(@PathVariable("chapterId") Integer chapter,
                                   @PathVariable("pageNum") Integer pageNum){
        return noteService.getVideoComment(chapter , pageNum);
    }

    @PostMapping("/note/save")
    public String saveNode(long updateTime ,
                           Integer videoId ,
                           Integer consumerId ,
                           String noteContent){
        Note note = new Note();
        Integer chapterId = ((Video) videoService.getVideoByVideoId(videoId).getdata()).getChapterId();
        note.setConsumerId(consumerId);
        note.setChapterId(chapterId);
        note.setNoteContent(noteContent);
        note.setUpdateTime(new Date(updateTime));
        ServiceResponse serviceResponse = noteService.saveVideoComment(note);
        if (serviceResponse.getCode() == 200)
            return "true";
        return "false";
    }

}
